package personal.xjl._23java1studentdemo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import personal.xjl._23java1studentdemo.mapper.TeacherMapper;
import personal.xjl._23java1studentdemo.model.Student;
import personal.xjl._23java1studentdemo.model.Teacher;
import personal.xjl._23java1studentdemo.service.TeacherService;


import java.util.List;

@Service  //类似于@Controller@Mapper,告诉spring容器帮忙创建一个service对象
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    TeacherMapper teacherMapper;
    @Override
    public List<Teacher> findAll() {
        return teacherMapper.selectAll();
    }
    @Override
    public int remove(int id) {
        return teacherMapper.deleteById(id);
    }

    @Override
    public int add(Teacher teacher) {
        return teacherMapper.insert(teacher);
    }

    @Override
    public Teacher findById(int id) {
        return teacherMapper.selectById(id);
    }

    @Override
    public int edit(Teacher teacher) {
        return teacherMapper.update(teacher);
    }

    @Override
    public List<Teacher> findByPage(int pageNo, int pageSize) {
        return teacherMapper.selectByPage((pageNo-1)*pageSize, pageSize);
    }

    @Override
    public boolean login(String username, String password) {
        return teacherMapper.selectByNameAndPwd(username,password)!=null;
    }
}